package com.sale.system.service.impl;

import com.sale.common.core.domain.model.LoginUser;
import com.sale.common.enums.YesOrNoEnum;
import com.sale.common.utils.SecurityUtils;
import com.sale.system.domain.TodoList;
import com.sale.system.mapper.TodoListMapper;
import com.sale.system.service.ITodoService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * 代办事项
 *
 * @author zhangyingdong
 * @version 1.0.0
 * @package com.sale.system.service.impl
 * @className TodoServiceImple
 * @date 2022-02-17  07:20
 */
@Service
public class TodoServiceImple implements ITodoService {

    @Resource
    private TodoListMapper todoListMapper;


    @Override
    public List<TodoList> list(TodoList todoList) {
        return todoListMapper.queryList(todoList);
    }

    @Override
    public int add(TodoList todoList) {
        LoginUser loginUser = SecurityUtils.getLoginUser();
        todoList.setCreateBy(loginUser.getUsername());
        todoList.setCreateTime(new Date());
        todoList.setDelInd(YesOrNoEnum.NO.getCodeStr());
        todoList.setDoInd(YesOrNoEnum.NO.getCodeStr());
        todoListMapper.insert(todoList);
        return YesOrNoEnum.YES.getCodeInt();
    }

    @Override
    public int update(TodoList todoList) {

        todoListMapper.updateByPrimaryKeySelective(todoList);
        return YesOrNoEnum.YES.getCodeInt();
    }

    @Override
    public int delete(Long id) {
        TodoList todoList = new TodoList();
        todoList.setDelInd(YesOrNoEnum.YES.getCodeStr());
        todoListMapper.updateByPrimaryKeySelective(todoList);
        return YesOrNoEnum.YES.getCodeInt();
    }

    @Override
    public int finish(Long id) {
        TodoList todoList = new TodoList();
        todoList.setId(id);
        todoList.setDoInd(YesOrNoEnum.YES.getCodeStr());
        todoListMapper.updateByPrimaryKeySelective(todoList);
        return YesOrNoEnum.YES.getCodeInt();
    }

    @Override
    public TodoList getTodo(Long id) {
        return todoListMapper.selectByPrimaryKey(id);
    }
}
